package com.zhang.boot.core.util;

import cn.hutool.core.util.StrUtil;
import com.zhang.boot.core.constants.ErrorEnum;
import com.zhang.boot.core.exception.BusinessException;

public class AssertUtil {

    /**
     * 判断序列值不能为空
     * @param charSequence
     * @param errorEnum
     */
    public static void notEmpty(CharSequence charSequence, ErrorEnum errorEnum) {
        if (StrUtil.isEmpty(charSequence)) {
            throw new BusinessException(errorEnum);
        }
    }

    /**
     * 判断序列值不能为空
     * @param object
     * @param errorEnum
     */
    public static void notEmpty(Object object, ErrorEnum errorEnum) {
        if (object == null) {
            throw new BusinessException(errorEnum);
        }
    }

    /**
     * 判断表达式是否为真
     * @param expression
     * @param errorEnum
     */
    public static void isTrue(boolean expression, ErrorEnum errorEnum) {
        if (!expression) {
            throw new BusinessException(errorEnum);
        }
    }
}
